<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'basic';
$return=array();
if($_RQ['op']=='basic'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$this->plugin_setting('basic',$postdata);
		//以公众号uniacid生成文件夹
		$dir = iconv("UTF-8", "GBK", ROOT_D.'/addons/jy_zhongchou/cert/'.$_SESSION['uniacid']);
			if (!file_exists($dir)){
				mkdir ($dir,0777,true);
			  //  echo '创建文件夹成功';
			} else {
			  //  echo '需创建的文件夹已经存在';
			}
		$id=intval($postdata['id']);
		$data=array();
		//上传cert证书
		if($postdata['cert']&&$postdata['key']){
			//print_r($postdata['cert']);exit;
			$certfilename=pdo_getcolumn('core_attachment',array('attachment'=>$postdata['cert']),'title');
			$keyfilename=pdo_getcolumn('core_attachment',array('attachment'=>$postdata['key']),'title');
			
			$certfile_data=cfc('files')->source_read($postdata['cert']);
			$keyfile_data=cfc('files')->source_read($postdata['key']);
			
			file_put_contents(ROOT_D.'/addons/jy_zhongchou/cert/'.$_SESSION['uniacid'].'/'.$certfilename.'.pem',$certfile_data);
			file_put_contents(ROOT_D.'/addons/jy_zhongchou/cert/'.$_SESSION['uniacid'].'/'.$keyfilename.'.pem',$keyfile_data);
			
			//exi('认证文件上传成功','error');
		}

		exi('设置成功');
	}
	$footernav =array(
		array('title'=>'首页','icon'=>'icon-shouye','action'=>'jy_zhongchou/index/'),
		array('title'=>'项目','icon'=>'icon-fenlei2','action'=>'jy_zhongchou/p_list/'),
		array('title'=>'我的','icon'=>'icon-wo1','action'=>'jy_zhongchou/home/'),
	);
	$plugins =$this->plugins();
	$return['item']=$this->plugin_setting('basic');
	$return['item']['footernav']=$return['item']['footernav']?$return['item']['footernav']:$footernav;
	$return['item']['plugins']=$return['item']['plugins']?$return['item']['plugins']:$plugins[1]['list'];
	$htmls=array(
		'type'=>'edit',
		'desc'=>'参数设置',
		'tabs'=>$tabs,
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'string','title'=>'标题','name'=>'title'),
					array('type'=>'text','title'=>'描述','name'=>'desc'),
					array('type'=>'image','title'=>'网站logo','name'=>'logo'),
					array('type'=>'string','title'=>'分享标题','name'=>'share_title'),
					array('type'=>'image','title'=>'分享图片','name'=>'share_image'),
					array('type'=>'string','title'=>'分享描述','name'=>'share_desc'),
					array('type'=>'image','title'=>'众筹详情页支付弹窗背景图','name'=>'pay_bg'),
				)
			),
			array(
				'title'=>'幻灯片',
					'list'=>array(
						array(
							'type'=>'array',
							'name'=>'hdps',
							'add_tip'=>'添加一个幻灯片',
								'list'=>array(
									array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片'),
									array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
									
								),
								'details'=>array(
									array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片','help'=>''),
									array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
									
								)
						)
					)
			),
			array(
				'title'=>'底部导航',
					'list'=>array(
									array('type'=>'array','name'=>'footernav','add_tip'=>'添加一个底部导航',
									'list'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'icon','name'=>'icon','from'=>'jinyunicon','title'=>'导航图标'),
										array('type'=>'string','name'=>'action','title'=>'导航链接'),							
									),
									'details'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'icon','name'=>'icon','from'=>'jinyunicon','title'=>'导航图标'),							
										array('type'=>'link','name'=>'action','title'=>'导航链接'),
									)
								),
					)
			),
			array(
				'title'=>'支付参数设置',
				'list'=>array(
					array('type'=>'string','title'=>'身份标识(AppId)','name'=>'appid'),
					array('type'=>'string','title'=>'微信支付商户号(MchId)','name'=>'mchid'),
					array('type'=>'string','title'=>'商户支付密钥(API密钥)','name'=>'apikey'),
					array('type'=>'upfile','title'=>'cert证书','name'=>'cert','help'=>'从商户平台上下载支付证书, 解压并取得其中的 apiclient_cert.pem，并在此处上传。'),
					array('type'=>'upfile','title'=>'key证书','name'=>'key','help'=>'从商户平台上下载支付证书, 解压并取得其中的 apiclient_key.pem，并在此处上传。'),
				
				)
			),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}


